import 'package:flutter/material.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:get/get.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/views/home/home_page.dart';
import 'package:xinxuan/views/review/my_page_temp.dart';
import 'package:xinxuan/views/service/service_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ReviewCommonPage extends StatelessWidget {

  final CommonPageController commonPageController = Get.find();

  /// 对应页面
  final List<Widget> _mainPage = [
    HomePage(), 
    ServicePage(), 
    MyPageTemp()
  ];

  /// 底部栏
  /// 底部导航栏
  List<Widget> _buildTabItemArr(int index) {
    List<Widget> widges = [
      _tabItem(
        index: 0,
        iconPath: index == 0 ? 'assets/icons/icon_common_home_selected.png' : 'assets/icons/icon_common_home.png', 
        title: '首页'
      ),
      _tabItem(
        index: 1,
        iconPath: index == 1 ? 'assets/icons/icon_service_selected.png' : 'assets/icons/icon_service.png', 
        title: '客服'
      ),
      _tabItem(
        index: 2,
        iconPath: index == 2 ? 'assets/icons/icon_common_me_selected.png' : 'assets/icons/icon_common_me.png',
        title: '我的'
      ),
    ];
    return widges;
  }

  /// 导航栏Item
  Widget _tabItem({required int index, required String iconPath, required String title}) {
    return InkWellUtil.shakeProofInkWell(Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Image.asset(
            iconPath,
            width: 24.w,
            height: 24.w
          ),
          Text(
            title,
            style: TextStyle(
              fontSize: 12.sp,
              color: textSubtitleColor
            ),
          )
        ],
      ),
    ), () {
      commonPageController.tabIndex.value = index;
      if (index == 3) {
        commonPageController.checkLogin(loading: false);
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    commonPageController.checkAppVersion(showLoading: false);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Obx(() => IndexedStack(
        index: commonPageController.tabIndex.value,
        children: _mainPage,
      )),
      bottomNavigationBar: BottomAppBar(
        shape: CircularNotchedRectangle(),
        child: Container(
          height: 56.h,
          child: Obx(() => Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: _buildTabItemArr(commonPageController.tabIndex.value),
          )),
        )
      ),
    );
  }
}